<!DOCTYPE html>
<html lang="cn">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <meta name="format-detection" content="telephone=no" />
    <meta name="format-detection" content="address=no" />
    <title>丸子妈妈-快速注册</title>
    <link rel="stylesheet" type="text/css" href="Public/Wap/v2/css/index.css?v=8" />
    <script src="Public/Wap/js/jquery-2.1.4.min.js?v=8"></script>
    <script src="Public/Wap/v2/js/adaptation.js"></script>    
    <script src="Public/Wap/js/common_v2.js?v=8"></script>
    <script src="Public/layer/layer.js?v=8"></script>
</head>
<body>
    <div id="wrap" class="pt detail-page houseFrm">
        <div class="header themeRed">
                快速注册
            <a href="javascript:window.history.back();" class="back"></a>
        </div>
        <p class="frmTips">为了保证服务质量，请先验证您的手机</p>
        <form class="frmBox">
            <dl>
                <dd class="icoTel"><input type="tel" id="phone" placeholder="请输入手机号"></dd>
                <dd class="icolock">
                    <input type="tel" id="code" class="tele" placeholder="请输入验证码">
                    <a class="hqyz" href="javascript:void(0);">获取验证码</a>
                </dd>
            </dl>
        </form>
        <div class="frmBtn">
            <a href="javascript:;" id="btn_sub" class="btnBig">提交</a>
        </div>        
    </div>
    <script>
            var registerUrl= "/wap.php?m=Wap&c=User&a=register";
            var smsUrl = "./api.php?m=api&c=Sms&a=sendSmsCode";
            var flag = 0;
        
            $(function(){
        
                $("#btn_sub").on("click", function () {
                    var phone = $("#phone").val(),code = $("#code").val();
                    if (!validatePhone(phone)) {
                        layer.msg('请填写正确的手机号码');
                        return false;
                    }
                    if(code.length != 4){
                        layer.msg("请填写正确的验证码");
                        return false;
                    }
        
                    $.getJSON(registerUrl, {phone:phone,code:code}, function(data){
                        if(data.status) {
                            layer.msg(data.msg);
                        }else{
                            layer.msg('注册成功');
                            window.history.go(-2);
                        }
                    });
                });
        
                $(".hqyz").on('click', function () {
                    var phone = $("#phone").val();
                    if (!validatePhone(phone)) {
                        layer.msg('请输入正确的手机号码');
                        return false;
                    }
                    if (!flag) return false;
                    $.getJSON(smsUrl, {phone:phone,bind:1}, function(data){
                        flagSendMsg = false;
                        layer.msg(data.msg);
                        if(data.status == 0) {
                            flag = false;
                            $('.hqyz').html('<font>60</font>秒后重新获取');
                            timer = setInterval(countDown, 1000);
                        }
                    });
                });
        
                var timer;
                var flag = true;
                var countDown = function CountDown() {
                    var maxtime = parseInt($(".hqyz font").html());
                    if(maxtime>0){
                        --maxtime;
                        $('.hqyz font').html(maxtime);
                    }else{
                        clearInterval(timer);
                        $('.hqyz').html('获取验证码');
                        flag = true;
                    }
                }
            });
        </script>
</body>
</html>